<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
include ("../../include/dbFunctions.php");
include ("../../include/image_slider.php");
include ("../../include/function.php");


if (isset($_SESSION['volunteer_id'])) {

    $volunteer_id = $_SESSION['volunteer_id'];


//get volunteer information
    $volunteer = "SELECT * FROM volunteer WHERE volunteer_id = $volunteer_id";
    $volunteer = executeSelectQuery($volunteer);

//select volunteer time slot
    $query = "SELECT time_id FROM time_preference WHERE volunteer_id='" . $volunteer_id . "'";
    $time_id = executeSelectQuery($query);
//select all education level
    $education = "SELECT * FROM education";
    $education = executeSelectQuery($education);
//select volunteer prefer education level
    $checked = "SELECT education_id FROM education_preference WHERE volunteer_id = $volunteer_id";
    $checked = executeSelectQuery($checked);
//select all location
    $location = "SELECT * FROM location";
    $location = executeSelectQuery($location);
//select volunteer location
    $selected = "SELECT location_id FROM location_preference WHERE volunteer_id = $volunteer_id";
    $selected = executeSelectQuery($selected);
}
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Junior Achievement Singapore</title>
        <link href="../../media/css/styles.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" language="javascript" src="../../media/js/jquery/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" language="javascript" src="../../media/js/jquery/jquery.validate.min.js"></script>
        <script type="text/javascript" src="../../media/js/jquery/image_slider.js"></script>
        <!-- Custom jquery scripts -->
        <script src="../../media/js/jquery/custom_jquery.js" type="text/javascript"></script>
        <script type="text/javascript" src="../../media/js/jquery/validator_rules.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $("#updateform").validate(volunteer_validate);

            } );

            function toggle1(source) { //for select all checkbox :)
                checkboxes = document.getElementsByName('tid[]');
                for each(var checkbox in checkboxes)
                checkbox.checked = source.checked;
            }

            function toggle2(source) { //for select all checkbox :)
                checkboxes = document.getElementsByName('education[]');
                for each(var checkbox in checkboxes)
                checkbox.checked = source.checked;
            }

            function toggle3(source) { //for select all checkbox :)
                checkboxes = document.getElementsByName('location[]');
                for each(var checkbox in checkboxes)
                checkbox.checked = source.checked;
            }
        </script>
    </head>
    <body>
        <script>
            var timeout    = 700;
            var closetimer = 0;
            var ddmenuitem = 0;

            function jsddm_open()
            {  jsddm_canceltimer();
                jsddm_close();
                ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

            function jsddm_close()
            {  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

            function jsddm_timer()
            {  closetimer = window.setTimeout(jsddm_close, timeout);}

            function jsddm_canceltimer()
            {  if(closetimer)
                {  window.clearTimeout(closetimer);
                    closetimer = null;}}

            $(document).ready(function()
            {  $('#navigation > li').bind('mouseover', jsddm_open)
                $('#navigation > li').bind('mouseout',  jsddm_timer)});

            document.onclick = jsddm_close;

        </script>
        <div id="container"><!--CONTAINER STARTS-->
            <div id="navigation">
                <li><a href="../../include/home/homepage.php">HOME</a></li>
                <li><a href="../../include/home/contact.php">CONTACT</a></li>
                <li><a href="http://ja.org.sg/">ABOUT JA SINGAPORE</a></li>
                <li><a href="http://jascheduling.lefora.com/">FEEDBACK</a></li>
                <li><a href="../../guide/guide_menu.php">HELP</a></li>

            </div>
            <div id="title"><!--TITLE STARTS-->
            </div><!--TITLE ENDS-->
            <div id="featured"><!--FEATURED AREA STARTS-->

                <div class="featured-image"><!--FEATURED IMAGE STARTS-->
                    <img alt="Featured Image" src="../../media/images/featured_image.png"/>
                </div><!--FEATURED IMAGE ENDS-->

                <div class="featured-text"><!--FEATURED TEXT STARTS-->

                    <h2>Welcome to JA Singapore</h2>
                    <p>Junior Achievement programs help prepare young people for the real world by showing them how to generate wealth and effectively manage it, how to create jobs which make their communities more robust, and how to apply entrepreneurial thinking to the workplace. <a href="http://www.jaworldwide.org/">Read More... </a></p>
                </div><!--FEATURED TEXT ENDS-->
            </div><!--FEATURED AREA ENDS-->
            <?php
            custom_login();
            ?>
            <div id="left-content"><!--RIGHT CONTENT STARTS-->

                <div class="left-top"><!--RIGHT CONTENT BOX TOP-->
                </div><!--RIGHT CONTENT BOX TOP ENDS-->

                <div class="left-middle"><!--RIGHT CONTENT BOX MIDDLE-->
                    <?php
                    if (!isset($_SESSION['volunteer_id'])) {
                        echo "<br/><br/><br/><br/><br/><center><h3>You don't have permission to view this page<h3><br/>
                           Please login to access the page.</center><br/><br/><br/><br/><br/><br/><br/><br/>";
                    } else {
                        ?>
                    <em>* Required fields</em><br/>
                    <h3>Personal Information</h3>
                    <!-- Print out volunteer current information and allow to edit-->
                    <form id="updateform" method="post" action="doUpdateAccount.php" enctype="multipart/form-data">
                        <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                            <tr>
                                <th valign="top">My Salutation<em>*</em>  </th>
                                <td> <select name="volunteer_salutation" class="styledselect_form_1">
                                            <?php
                                            $sal_array = array('Mr.', 'Mrs.', 'Ms.', 'Dr.');

                                            for ($i = 0; $i < count($sal_array); $i++) {

                                                if ($volunteer[0]['volunteer_salutation'] == $sal_array[$i]) {
                                                    ?>
                                        <option value="<?php echo $sal_array[$i] ?>" selected="yes" ><?php echo $sal_array[$i] ?></option>
                                                    <?php
                                                } else {
                                                    ?>
                                        <option value="<?php echo $sal_array[$i] ?>" ><?php echo $sal_array[$i] ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                    </select></td>
                            </tr>
                            <tr>
                                <th valign="top">My First Name<em>*</em> </th>
                                <td><input type="text" name="volunteer_firstname" value="<?php echo $volunteer[0]['volunteer_firstname'] ?>" class="inp-form"/></td>

                            </tr>
                            <tr>
                                <th valign="top">My Family Name<em>*</em> </th>
                                <td><input type="text" name="volunteer_surname" value="<?php echo $volunteer[0]['volunteer_surname'] ?>" class="inp-form"/></td>
                            </tr><tr>
                                <th valign="top">My Gender<em>*</em>  </th>
                                <td> <select name="volunteer_gender" class="styledselect_form_1" >
                                            <?php
                                            $gen_array = array('Male', 'Female');

                                            for ($i = 0; $i < count($gen_array); $i++) {

                                                if ($volunteer[0]['volunteer_gender'] == $gen_array[$i]) {
                                                    ?>
                                        <option value="<?php echo $gen_array[$i] ?>" selected="yes" ><?php echo $gen_array[$i] ?></option>
                                                    <?php
                                                } else {
                                                    ?>
                                        <option value="<?php echo $gen_array[$i] ?>" ><?php echo $gen_array[$i] ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                    </select></td>
                            </tr>
                            <tr>
                                <th valign="top">My Organization<em>*</em>  </th>
                                <td> <select name="sponsor_id" class="styledselect_form_1">
                                            <?php
                                            $sponsor = "SELECT sponsor_id, sponsor_name FROM sponsor";
                                            $sponsor = executeSelectQuery($sponsor);

                                            for ($i = 0; $i < count($sponsor); $i++) {
                                                if ($volunteer[0]['sponsor_id'] == $sponsor[$i]['sponsor_id']) {
                                                    ?>
                                        <option  selected="yes" value="<?php echo $sponsor[$i]['sponsor_id'] ?>"><?php echo $sponsor[$i]['sponsor_name'] ?></option>
                                                    <?php
                                                } else {
                                                    ?>
                                        <option value="<?php echo $sponsor[$i]['sponsor_id'] ?>"><?php echo $sponsor[$i]['sponsor_name'] ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                    </select></td>
                            </tr>
                            <tr>
                                <th valign="top">My Profession<em>*</em> </th>
                                <td><input type="text" name="volunteer_profession" value="<?php echo $volunteer[0]['volunteer_profession'] ?>" class="inp-form"/></td>

                            </tr>
                            <tr>
                                <th valign="top">Years of working<em>*</em> </th>
                                <td><input class="inp-form" type ="text" name = "volunteer_experience" value = "<?php echo $volunteer[0]['volunteer_experience'] ?>" /></td>
                            </tr>
                            <tr>
                                <th valign="top">How I know about JA <em>*</em></th>
                                <td><textarea rows="5" cols="22" name ="volunteer_reference"><?php echo $volunteer[0]['volunteer_reference '] ?></textarea></td>
                            </tr>
                            <tr>
                                <th valign="top">Resume</th>
                                <td><input class="inp-form" type="file" name="uploadfile" id="file" /> </td>
                            </tr>
                        </table>
                        
                        <br/><br/>
                        <h3>Contact Information</h3><br/>
                        <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                            <tr>
                                <th valign="top">Mobile Phone<em>*</em> </th>
                                <td><input type="text" name="volunteer_mobile" value="<?php echo $volunteer[0]['volunteer_mobile'] ?>" class="inp-form"/></td>

                            </tr>
                            <tr>
                                <th valign="top">Office Phone </th>
                                <td><input type="text" name="volunteer_office" value="<?php echo $volunteer[0]['volunteer_office'] ?>" class="inp-form"/></td>
                            </tr>
                            <tr>
                                <th valign="top">My Email<em>*</em> </th>
                                <td><input type="text" name="volunteer_email" value="<?php echo $volunteer[0]['volunteer_email'] ?>" class="inp-form"/></td>

                            </tr>
                            <tr>
                                <th valign="top">Password<em>*</em> </th>
                                <td><input type="password" name="volunteer_password" value="__________" id ="contact_password" class="inp-form"/></td>
                            </tr>
                            <tr>
                                <th valign="top">Retype-Password<em>*</em> </th>
                                <td><input type="password" name="retype_password" value="__________" class="inp-form"/></td>
                            </tr>

                            <tr>
                        </table>
                        <br/><br/>
                        <h3>Preference Information</h3><br/>
                        <br/>
                        <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                            <tr>
                                <th valign="top">My Preferred Educational Level: <em>*</em></th>
                                <td>
                                    <br>
                                            <?php
                                            for ($i = 0; $i < count($education); $i++) {
                                                $tick = '';
                                                for ($t = 0; $t < count($checked); $t++) {
                                                    if ($education[$i]['education_id'] == $checked[$t]['education_id']) {
                                                        $tick = "checked";
                                                    }
                                                }
                                                ?>
                                        <input  type="checkbox" class="require-edu validate-checkbox-edu-oneormore" <?php echo $tick ?> name ="education[]" value="<?php echo $i ?>"/> <?php echo $education[$i]['education_name'] ?> <br/>
                                                <?php
                                            }
                                            ?>
                                </td>
                            </tr>
                            <tr>
                                <th valign="top">My Preferred Day:<em>*</em></th>

                                <td> <select name="time_id" class="styledselect_form_1">
                                            <?php
                                            $time = "SELECT time_id, time_name FROM time";
                                            $time = executeSelectQuery($time);
                                            if (count($time_id) == 1) {
                                                for ($i = 0; $i < count($time); $i++) {
                                                    if ($time_id[0]['time_id'] == $time[$i]['sponsor_id']) {
                                                        ?>
                                        <option  selected="yes" value="<?php echo $time[$i]['time_id'] ?>"><?php echo $time[$i]['time_name'] ?></option>
                                                        <?php
                                                    } else {
                                                        ?>
                                        <option value="<?php echo $time[$i]['time_id'] ?>"><?php echo $time[$i]['time_name'] ?></option>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                        <option value="2">No preference</option>
                                                <?php
                                            } else {
                                                ?>
                                        <option value="N">No preference</option>
                                        <option value="D">Weekday</option>
                                        <option value="K">Weekend</option>
                                                <?php
                                            }
                                            ?>
                                    </select></td>

                            </tr>
                            <tr>
                                <th valign="top">My Preferred Location: <em>*</em> <INPUT type="button" value="" class="form-help" onClick="window.open('../../include/singaporeArea.php','mywindow','width=520,height=340')"></th>
                                <td>

                                        <?php
                                        for ($i = 0; $i < count($location); $i++) {
                                            $check = '';
                                            for ($t = 0; $t < count($selected); $t++) {
                                                if ($selected[$t]['location_id'] == $location[$i]['location_id']) {
                                                    $check = "checked";
                                                }
                                            }
                                            ?>

                                    <input type ="checkbox" class="require-location validate-checkbox-location-oneormore" <?php echo $check ?> name ="location[]" value="<?php echo $i; ?>" /> <?php echo $location[$i]['location_name'] ?><br/>
                                            <?php
                                        }
                                        ?>
                                </td>
                            </tr>
                        </table>
                        <br><br>
                                    <?php $pass = $volunteer[0]['volunteer_password'] ?>
                                <table>
                                    <td> <input type="button" value="" class="form-back" onClick="window.location.href='volunteerdetail.php'"/></td>
                                    <td><input type="submit" value="" class="form-submit"/></td>
                                    <td><input type="reset" value="" class="form-reset"/></td>
                                </table>
                                <input type="hidden" name="pass" value="<?php echo $pass ?>">
                                    </form>
                                        <?php
                                    }
                                    ?>
                                    </div><!--RIGHT CONTENT BOX MIDDLE ENDS-->
                                    <div class="left-bottom"><!--RIGHT CONTENT BOX BOTTOM-->
                                    </div><!--RIGHT CONTENT BOX BOTTOM ENDS-->
                                    </div><!--RIGHT CONTENT ENDS-->
                                    </div><!--CONTAINER ENDS-->
                                    <div id="footer"><!--FOOTER STARTS-->
                                        <p>Copyright &copy; Junior Achievement Singapore | All Rights Reserved</p>
                                    </div><!--FOOTER ENDS-->

                                    </body>
                                    </html>
